package yxy.apple.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * @author James
 * @date 2022/1/23 9:07
 **/
public class StringTrans {
    //String转boolean
    public static boolean[] string2BooleanArray(String str){
        if (StringUtillity.isEmpty(str)) return new boolean[0];

        String[] tmp = str.split(",");
        boolean[] boos = new boolean[tmp.length];
        for(int j=0;j<tmp.length;j++){
            boos[j] = Boolean.parseBoolean(tmp[j]);
        }
        return boos;
    }

    //boolean数组转String
    public static String booleanArray2String(boolean booleanArray[]){
        String str = "";
        for(int i=0; i<booleanArray.length; i++){
            str = str + String.valueOf(booleanArray[i]) + ",";
        }
        if (str.length() > 0) str = str.substring(0, str.length()-1);
        return str;
    }

    public static Integer[] string2IntegerArray(String str){
        if (StringUtillity.isEmpty(str)) return new Integer[0];

        String[] tmp = str.split(",");
        Integer[] ints = new Integer[tmp.length];
        for(int j=0;j<tmp.length;j++){
            ints[j] = Integer.parseInt(tmp[j]);
        }
        return ints;
    }

    public static String IntegerArray2String(Integer[] ints){
        String tmp = "";
        for(int i=0;i<ints.length;i++){
            tmp = tmp + ints[i] + ",";
        }
        if (tmp.length() > 0) tmp = tmp.substring(0, tmp.length()-1);
        return tmp;
    }

    public static ArrayList<Integer> string2ArrayList(String str){
        if (StringUtillity.isEmpty(str)) return new ArrayList<>();

        String[] tmp = str.split(",");
        ArrayList<Integer> ints = new ArrayList<>();
        for(int j=0;j<tmp.length;j++){
            ints.add(Integer.parseInt(tmp[j]));
        }
        return ints;
    }

    public static String arrayList2String(ArrayList<Integer> arrs){
        String tmp = "";
        if (arrs == null) return tmp;

        for (int i=0;i<arrs.size();i++){
            tmp = tmp + arrs.get(i) + ",";
        }
        if (tmp.length() > 0) tmp = tmp.substring(0, tmp.length()-1);
        return tmp;
    }

    public static String set2String(Set<String> sets){
        String tmp = "";
        for(String str:sets){
            tmp = tmp + str + ",";
        }
        if (tmp.length() > 0) tmp = tmp.substring(0, tmp.length() - 1);
        return tmp;
    }

    public static Set<String> string2Set(String str){
        if (StringUtillity.isEmpty(str)) return new HashSet<>();

        String[] tmp = str.split(",");
        Set<String> sets = new HashSet<>();
        for(int i = 0; i < tmp.length ; i++){
            sets.add(tmp[i]);
        }
        return sets;
    }

    public static void main (String[] args) {
//        Set<String> sets = new HashSet<>();
//        sets.add("1");
//        sets.add("2");
//        String res = set2String(sets);
//        System.out.println(res);
//
//        string2Set(res);
//
//        ArrayList<Integer> arrs = new ArrayList<>();
//        arrs.add(1503);
//        arrayList2String(arrs);

        string2ArrayList("");
    }

}
